﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Web.Http.ModelBinding;

namespace shopruvi.Areas.Admin.Controllers
{
    public class BaseController : ApiController
    {
        public IOrderedEnumerable<string> ErrorList(ModelStateDictionary obj)
        {
            return obj.Keys.SelectMany(k => ModelState[k].Errors).Where(m => !string.IsNullOrWhiteSpace(m.ErrorMessage))
                              .Select(m => m.ErrorMessage).ToArray().OrderBy(m => m.Length);
        }

        public ModelStateDictionary RemoveError(ModelStateDictionary obj)
        {
            obj.Remove("obj.Id");
            return obj;
        }
    }
}
